package com.d3works.apps.sale.web;

import com.d3works.apps.sale.db.AdvancePayment;
import com.d3works.apps.sale.db.repo.AdvancePaymentRepository;
import com.d3works.apps.sale.service.AdvancePaymentService;
import com.d3works.exception.D3worksException;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Singleton;

@Singleton
public class AdvancePaymentController {

  public void cancelAdvancePayment(ActionRequest request, ActionResponse response)
      throws D3worksException {
    AdvancePayment advancePayment = request.getContext().asType(AdvancePayment.class);
    advancePayment = Beans.get(AdvancePaymentRepository.class).find(advancePayment.getId());

    Beans.get(AdvancePaymentService.class).cancelAdvancePayment(advancePayment);

    response.setReload(true);
  }
}
